package com.fengyi.homefurnish.controller;

import com.fengyi.homefurnish.pojo.ProAttrName;
import com.fengyi.homefurnish.pojo.ProAttrType;
import com.fengyi.homefurnish.pojo.ProAttrValue;
import com.fengyi.homefurnish.service.ProAttrNameService;
import com.fengyi.homefurnish.service.ProAttrTypeService;
import com.fengyi.homefurnish.service.ProAttrValueService;
import com.fengyi.homefurnish.utils.Log;
import com.fengyi.homefurnish.utils.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品属性控制层
 */
@RestController
@RequestMapping("/proAttr")
public class ProAttrController {

    @Resource
    private ProAttrNameService proAttrNameService;

    @Resource
    private ProAttrValueService proAttrValueService;

    @Resource
    private ProAttrTypeService proAttrTypeService;


    @RequestMapping("/getAllPro")
    public Pager<ProAttrName> getAllList(Integer offset, Integer limit, ProAttrName proAttrName){
        return proAttrNameService.getProAttrNamePager(offset,limit,proAttrName);
    }

    @RequestMapping("/getProAttrValPager")
    public Pager<ProAttrValue> getProAttrValPager(Integer offset, Integer limit, ProAttrValue proAttrValue){
        return proAttrValueService.getProAttrNamePager(offset,limit,proAttrValue);
    }

    @RequestMapping("/addProAttrName")
    public Integer addProAttrName(ProAttrName proAttrName){
        Integer result;
        try{
            result = proAttrNameService.addProAttrName(proAttrName);
        }catch (Exception e){
            result = -1;
            Log.LOGGER.error("添加商品属性名失败："+e.getMessage());
        }
        return result;
    }

    @RequestMapping("/getAllProAttrType")
    public List<ProAttrType> getAllProAttrType(){
        return proAttrTypeService.getAllAttrType();
    }

    @RequestMapping("/updateProAttrName")
    public Integer updateProAttrName(ProAttrName proAttrName){
        return proAttrNameService.updateProAttrName(proAttrName);
    }

    @RequestMapping("/updateProAttrNameState")
    public Integer updateProAttrNameState(ProAttrName proAttrName){
        return proAttrNameService.updateProAttrNameState(proAttrName);
    }
}
